package homework.threadwork2.coding;

import static java.lang.Thread.sleep;

public class ReadWeather implements Runnable {
    Weather w;

    public ReadWeather(Weather w) {
        this.w = w;
    }

    @Override
    public void run() {
        synchronized (this.w)
        {
        for(int i=0;i<10;i++){
//            if (this.w.getFlag()) {
////                System.out.println("正在生成天气："+this.w.getFlag());
//                try {
//                    this.w.wait();
//
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
//            System.out.println("开始读取天气");
            System.out.printf("读取天气数据 温度%d 湿度%d\n", this.w.getTemp(), this.w.getHumidity());
            System.out.println("================");
            try {
                this.w.setFlag(true);
//                this.w.notifyAll();
                sleep(1000);
//                notifyAll();


            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }}
}
